home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_02 / ALLISON.ZIP / RANGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-01  |  634 b   |  28 lines

  1. LISTING 2 -  Uses <limits.h> to choose a suitable numeric type
  2. /* range.c */
  3. #include <stdio.h>
  4. #include <limits.h>
  5.  
  6. #define LOWER_BOUND  <your min here>
  7. #define UPPER_BOUND  <your max here>
  8.  
  9. /* Determine minimal numeric type for range */
  10. #if LOWER_BOUND < LONG_MIN || LONG_MAX < UPPER_BOUND
  11.     typedef double Num_t;
  12. #elif LOWER_BOUND < INT_MIN || INT_MAX < UPPER_BOUND
  13.     typedef long Num_t;
  14. #elif LOWER_BOUND < SCHAR_MIN || SCHAR_MAX < UPPER_BOUND
  15.     typedef int Num_t;
  16. #else
  17.     typedef signed char Num_t;
  18. #endif
  19.  
  20. main()
  21. {
  22.     Num_t x;
  23.  
  24.     printf("sizeof(Num_t) == %d\n",sizeof x);
  25.     return 0;
  26. }
  27.  
  28.